package com.estar.assistsurvy.adapter;

import java.util.ArrayList;

import com.estar.assistsurvy.R;
import com.estar.assistsurvy.entity.Item;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SidebarListviewAdapter extends BaseAdapter {

	private ArrayList<Item> list;
	private LayoutInflater inflater;
	
	public SidebarListviewAdapter(Context context, ArrayList<Item> list) {
		super();
		this.list = list;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint("InflateParams") @Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v;
		ViewHolder holder;
		if(convertView==null){
			v=inflater.inflate(R.layout.listview_sidebar, null);
			holder=new ViewHolder();
			holder.listItem_img=(ImageView) v.findViewById(R.id.listItem_img);
			holder.listItem_txt=(TextView) v.findViewById(R.id.listItem_txt);
			v.setTag(holder);
		}else{
			v=convertView;
			holder=(ViewHolder) v.getTag();
		}
		
		Item item=list.get(position);
		holder.listItem_img.setImageResource(item.getImg());
		holder.listItem_txt.setText(item.getText());
		return v;
	}
	
	private class ViewHolder{
		ImageView listItem_img;
		TextView listItem_txt;
	}

}
